package cn.org.book.shop.web.controller.article;

import java.util.List;

import cn.org.book.shop.article.domain.ApUser;
import cn.org.book.shop.article.service.IApUserService;
import cn.org.book.shop.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.org.book.shop.common.annotation.Log;
import cn.org.book.shop.common.core.controller.BaseController;
import cn.org.book.shop.common.core.domain.AjaxResult;
import cn.org.book.shop.common.enums.BusinessType;
import cn.org.book.shop.common.core.page.TableDataInfo;

/**
 * 用户基础数据Controller
 *
 * @author wanghongjie
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/ap/user")
public class ApUserController extends BaseController {
    @Autowired
    private IApUserService apUserService;

    /**
     * 查询用户基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('ap:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApUser apUser) {
        startPage();
        List<ApUser> list = apUserService.selectApUserList(apUser);
        return getDataTable(list);
    }

    /**
     * 导出用户基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('ap:user:export')")
    @Log(title = "用户基础数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ApUser apUser) {
        List<ApUser> list = apUserService.selectApUserList(apUser);
        ExcelUtil<ApUser> util = new ExcelUtil<>(ApUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取用户基础数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('ap:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(apUserService.selectApUserById(id));
    }

    /**
     * 新增用户基础数据
     */
    @PreAuthorize("@ss.hasPermi('ap:user:add')")
    @Log(title = "用户基础数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApUser apUser) {
        return toAjax(apUserService.insertApUser(apUser));
    }

    /**
     * 修改用户基础数据
     */
    @PreAuthorize("@ss.hasPermi('ap:user:edit')")
    @Log(title = "用户基础数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApUser apUser) {
        return toAjax(apUserService.updateApUser(apUser));
    }

    /**
     * 删除用户基础数据
     */
    @PreAuthorize("@ss.hasPermi('ap:user:remove')")
    @Log(title = "用户基础数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(apUserService.deleteApUserByIds(ids));
    }
}
